package com.xxyy.mylive;

import android.app.Application;
import android.content.Context;

import com.qiniu.pili.droid.streaming.StreamingEnv;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.xxyy.mylive.bean.BaseBean;
import com.xxyy.mylive.bean.WxUserInfo;

/**
 * 全局Application
 * Created by ado on 21:29 2016/10/19.
 */
public class MyApplication extends Application {
    private WxUserInfo userInfo;
    private IWXAPI wxApi;

    @Override
    public void onCreate() {
        super.onCreate();
        initStream();
        initWxApi();
    }

    /**
     * 初始化推流
     */
    private void initStream() {
        StreamingEnv.init(getApplicationContext());
    }

    private void initWxApi() {
        String appId= getResources().getString(R.string.weixin_app_id);
        wxApi = WXAPIFactory.createWXAPI(this,appId,true);
        wxApi.registerApp(appId);
    }

    public IWXAPI getWxApi() {
        return wxApi;
    }

    /**
     * w保存app全局用户信息
     *
     * @param bean
     */
    public void saveUserInfo(BaseBean bean) {
        if (bean instanceof WxUserInfo) {
            userInfo = (WxUserInfo) bean;
        }
    }

    public BaseBean getUserInfo() {
        return userInfo;
    }
}
